//
//  MyHeaderView.m
//  HAODE
//
//  Created by panquanReabam.com on 16/5/12.
//  Copyright © 2016年 reabam.com. All rights reserved.
//

#import "MyHeaderView.h"
@interface MyHeaderView()
@end

@implementation MyHeaderView
@synthesize mDelegate;


- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        UIImageView* heardimage=[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, 160)];
        heardimage.image=[UIImage imageNamed:@"wodebeijing"];
        [self addSubview:heardimage];
        UIImageView* heardimage1=[[UIImageView alloc]initWithFrame:CGRectMake(18, 110/2, 145/2, 145/2)];
        heardimage1.image=[UIImage imageNamed:@"logoyuanhuansss"];
        [self addSubview:heardimage1];
        _imageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 132.5/2, 132.5/2)];
        _imageView.layer.masksToBounds = YES;
        _imageView.layer.cornerRadius = 132.5/2/2;
        _imageView.center= heardimage1.center;
        _imageView.contentMode = UIViewContentModeScaleToFill;
        _imageView.layer.borderColor = [UIColor whiteColor].CGColor;
        _imageView.layer.borderWidth = 0;
        [self addSubview:_imageView];
        _userName=[[UIButton alloc]init];
        _userName.contentHorizontalAlignment = UIControlContentHorizontalAlignmentFill;
        _userName.titleLabel.font=[UIFont systemFontOfSize:18];
        [self addSubview:_userName];
        _userType=[[UILabel alloc]init];
        _userType.textColor=[UIColor whiteColor];
        _userType.textAlignment=NSTextAlignmentCenter;
        _userType.backgroundColor = [UIColor colorWithRed:190/255.0 green:168/255.0 blue:39/255.0 alpha:0.66];
        _userType.font=[UIFont systemFontOfSize:12];
        [self addSubview:_userType];
        _companyName=[[UILabel alloc]initWithFrame:CGRectMake(200/2, 196/2, 200, 14)];
        _companyName.textColor=[UIColor whiteColor];
        _companyName.font=[UIFont systemFontOfSize:14];
        _companyName.numberOfLines=0;
        [self addSubview:_companyName];

    }
    return self;
}

-(void)setModel:(MemberListModel *)model{
    
    [_certificationBtn removeFromSuperview];
    [_userType removeFromSuperview];
    [_userName removeFromSuperview];
    [_companyName removeFromSuperview];
    [_Button removeFromSuperview];
    
    if ([[model.userDict objectForKey:@"userStatus"]isEqualToString:@"Y"]) {
        
         [_imageView setImageWithURL:[NSURL URLWithString:[model.userDict objectForKey:@"headImageUrl"]] placeholderImage:[UIImage imageNamed:@"touxiang_weidenglu"]];
        _certificationBtn= [[UIButton alloc]init];
        [_certificationBtn addTarget:self action:@selector(store) forControlEvents:UIControlEventTouchUpInside];
        _certificationBtn.backgroundColor=[UIColor clearColor];
        _certificationBtn.frame=CGRectMake(ScreenWidth-40, 160/2, 33, 33);
        [_certificationBtn setImage:[UIImage imageNamed:@"shouqi"] forState:UIControlStateNormal];
        [self addSubview:_certificationBtn];
        
        NSString *s2 =[NSString stringWithFormat:@"%@",  [model.userDict objectForKey:@"userName"]];
        UIFont *font2 = [UIFont systemFontOfSize:18];
        CGSize size2 = CGSizeMake(ScreenWidth-60, 2000);
        CGSize labelsize2 = [s2 sizeWithFont:font2 constrainedToSize:size2 lineBreakMode:NSLineBreakByCharWrapping];
        NSString *s =[NSString stringWithFormat:@"%@",  [model.userDict objectForKey:@"userTypeName"]];
        UIFont *font = [UIFont systemFontOfSize:18];
        CGSize size = CGSizeMake(ScreenWidth-60, 2000);
        CGSize labelsize = [s sizeWithFont:font constrainedToSize:size lineBreakMode:NSLineBreakByCharWrapping];
       
        _userName=[[UIButton alloc]init];
        _userName.frame=CGRectMake(200/2, 145/2, labelsize2.width, 18);
        [_userName setTitle:[NSString stringWithFormat:@"%@",  [model.userDict objectForKey:@"userName"]] forState:UIControlStateNormal];
        [_userName setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
         [self addSubview:_userName];
         _userType=[[UILabel alloc]init];
        _userType.frame=CGRectMake(_userName.right+5, 146/2, labelsize.width, 16);
        _userType .text=s ;
        _userType.textColor=[UIColor whiteColor];
        _userType.textAlignment=NSTextAlignmentCenter;
        _userType.backgroundColor = [UIColor colorWithRed:190/255.0 green:168/255.0 blue:39/255.0 alpha:0.66];
        _userType.font=[UIFont systemFontOfSize:12];
        [self addSubview:_userType];
         _companyName=[[UILabel alloc]init];
        _companyName.frame=CGRectMake(200/2, 196/2, 200, 14);
        _companyName.textColor=[UIColor whiteColor];
        _companyName.font=[UIFont systemFontOfSize:14];
        _companyName.numberOfLines=0;
        _companyName .text=[NSString stringWithFormat:@"%@", [model.userDict objectForKey:@"companyName"]]  ;
        [self addSubview:_companyName];
        [_Button removeFromSuperview];
        _Button=[[UIButton alloc]initWithFrame:CGRectMake(140, 0, ScreenWidth-140,130)];
        [_Button addTarget:self action:@selector(store) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:_Button];
    
        
    }else{
        
        NSLog(@"%@",model.userDict);
    
        _userName=[[UIButton alloc]initWithFrame:CGRectMake(100, 80, 200, 18)];
        _userName.contentHorizontalAlignment = UIControlContentHorizontalAlignmentFill;
        [_userName setTitle:[model.userDict objectForKey:@"userName"] forState:UIControlStateNormal];
        [_userName setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        _userName.titleLabel.font=[UIFont systemFontOfSize:18];
        [self addSubview:_userName];
        _certificationBtn= [[UIButton alloc] initWithFrame:CGRectMake(ScreenWidth-80, 75, 65, 24)];
        _certificationBtn.titleLabel.font=[UIFont systemFontOfSize:13];
        _certificationBtn.backgroundColor=luseColor;
        [_imageView setImageWithURL:[NSURL URLWithString:[model.userDict objectForKey:@"headImageUrl"]] placeholderImage:[UIImage imageNamed:@"touxiang_weidenglu"]];
        if ([[model.userDict objectForKey:@"userStatus"] isEqualToString:@"E"]) {
            [_certificationBtn setTitle:@"去认证" forState:UIControlStateNormal];
            [_certificationBtn addTarget:self action:@selector(certificationBtn:) forControlEvents:UIControlEventTouchUpInside];
        }
        if ([[model.userDict objectForKey:@"userStatus"] isEqualToString:@"W"]) {
            [_certificationBtn removeFromSuperview];
             [_Button removeFromSuperview];
             _userName.frame=CGRectMake(100, 75, 200, 18);
            _certificationBtn= [[UIButton alloc] initWithFrame:CGRectMake(100, 100, 150, 14)];
            _certificationBtn.titleLabel.font=[UIFont systemFontOfSize:14];
            [_certificationBtn setTitleColor:[UIColor colorWithRed:238/255.0 green:238/255.0 blue:53/255.0 alpha:1.0] forState:UIControlStateNormal]  ;
            [_certificationBtn setTitle:@"认证中..." forState:UIControlStateNormal];
            _certificationBtn.contentHorizontalAlignment= UIControlContentHorizontalAlignmentLeft;
            
        }
        [self addSubview:_certificationBtn];

}
}

-(void)store{

    [mDelegate store:@""];

}
-(void)certificationBtn:(UIButton*)sender{
    
    [mDelegate certificationBtn:@""];
}
@end
